package com.wyy.mall.tiny.controller;

import com.wyy.mall.tiny.common.api.CommonResult;
import com.wyy.mall.tiny.dto.OssCallbackResult;
import com.wyy.mall.tiny.dto.OssPolicyResult;
import com.wyy.mall.tiny.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * oss相关操作接口
 * created by 伍猷煜 on 2021/5/26 22:36 星期三
 */
@Controller
@Api(tags = "OssController", description = "Oss管理")
@RequestMapping("/aliyun/oss")
public class OssController {

    @Autowired
    private OssService mOssService;

    // web前端请求的
    @ApiOperation(value = "oss上传签名生成")
    @GetMapping("/policy")
    @ResponseBody
    public CommonResult<OssPolicyResult> policy() {
        return CommonResult.success(mOssService.policy());
    }

    // TODO 需要前端来测试一下
    // 这个接口是oss服务请求的
    @ApiOperation(value = "oss上传成功回调")
    @PostMapping("/callback")
    @ResponseBody
    public CommonResult<OssCallbackResult> callback(HttpServletRequest request) {
        return CommonResult.success(mOssService.callback(request));
    }

}
